﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DHLPricing.BaseInfo
{
    public partial class Customer : Form
    {
        public List<Service.Customers.Customer> AllCustomers = new List<Service.Customers.Customer>();
        Service.Customers.CustomerSoapClient customerService = new Service.Customers.CustomerSoapClient();
        public Customer()
        {
            AllCustomers = customerService.GetALL().ToList();

            InitializeComponent();
        }


        private void Customer_Load(object sender, EventArgs e)
        {
            dataGridView1.Visible = false;

        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            dataGridView1.Visible = true;

            bindGV();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {

            AddCustomer AddWin = new AddCustomer();
            AddWin.ShowDialog();

            dataGridView1.Visible = true;

           
            
        }

        void bindGV()
        {
            dataGridView1.AutoGenerateColumns = false;

            String code = txtCode.Text.Trim();
            String name = txtCName.Text.Trim();

            AllCustomers = customerService.GetALL().ToList();

            List<Service.Customers.Customer> list = (from info in AllCustomers
                                                     where info.Code.Contains(code) && info.CName.Contains(name)
                                                     select info).ToList();
            dataGridView1.DataSource = list;
        }

        private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)
            {
                DataGridView dgv = (DataGridView)sender;
                if (dgv.Rows[e.RowIndex].Cells["Code"].Value != null)
                {
                    EditCustomer ec = new EditCustomer(dgv.Rows[e.RowIndex].Cells["Code"].Value.ToString(), AllCustomers);
                    ec.ShowDialog();
                    bindGV();
                }
            }
        }
    }
}

